package com.talkweb.newproject.admin.sysorg.service;

import com.talkweb.newproject.admin.sysorg.dao.SysOrgDao;
import com.talkweb.newproject.admin.sysorg.dto.SysOrgDTO;
import com.talkweb.newproject.admin.sysuser.dto.SysUserDTO;
import org.apache.commons.collections.map.HashedMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by qsf on 2019/4/18.
 */
@Service
public class SysOrgService implements Serializable {
    @Autowired
    private SysOrgDao sysOrgDao;

    /**
     * 新增组织信息
     */
    @Transactional(rollbackFor = {Exception.class})
    public Long insertSysOrg(SysOrgDTO sysOrg) throws Exception {
        Map<String,Object> paramsMap = new HashMap<>();
        paramsMap.put("dto",sysOrg);
        int count = sysOrgDao.insertSysOrg(paramsMap);
        SysOrgDTO resultDTO = (SysOrgDTO) paramsMap.get("dto");
        return resultDTO.getId();
    }

    /**
     * 更改组织信息
     */
    @Transactional(rollbackFor = {Exception.class})
    public void updateSysOrg(SysOrgDTO sysOrgDTO) throws Exception {
        Map<String,Object> paramsMap = new HashedMap();
        paramsMap.put("dto",sysOrgDTO);
        sysOrgDao.updateSysOrg(paramsMap);

    }



    /**
     * 根据id查询组织信息
     */
    public SysOrgDTO querySysOrgDtoByPrimaryKey(String id) throws Exception {
        SysOrgDTO result  = sysOrgDao.querySysOrgDtoByPrimaryKey(id);
        if(result==null) {
            result = new SysOrgDTO();
        }
        return result;
    }

    /**
     * 根据id删除组织信息
     */
    public boolean deleteOrgById(String id) throws Exception{
        Integer count = sysOrgDao.deleteSysOrgById(id);
        if(count>0) {
            return true;
        }else {
            return false;
        }
    }

    public SysOrgDTO queryLikeSysOrg(SysOrgDTO obj) throws Exception {
        Map<String,Object> params = new HashMap<>();
        params.put("dto",obj);
        return sysOrgDao.queryLikeSysOrg(params);
    }

    public List<SysOrgDTO> searchSysOrg(SysOrgDTO obj) throws Exception{
        Map<String,Object> params = new HashMap<>();
        params.put("dto",obj);
        return sysOrgDao.searchSysOrg(params);
    }
}
